// QQMapKey是在腾讯地图开放平台设置的密钥
const QQMAPKEY = "EP4BZ-XUGKZ-YN5XA-ZEQAV-X7ETH-VLBKA";

/**
 * 根据经纬度，逆地址解析
 * @param lat 
 * @param lon 
 */
export const conversionAddress = (lat: number, lon: number) => {
  wx.request({
    // 腾讯地图转换接口
    url: "https://apis.map.qq.com/ws/geocoder/v1",
    data: {
      key: QQMAPKEY,
      location: `${lat},${lon}`
    },
    success(res) {
      // console.log('逆转换后的地址', res);
      const { data } = res;
      const { message, result } = data as any;
      if (message === "query ok") {
        const { address, address_component } = result;
        const { nation, province, city, district, street, street_number } =
          address_component;
        const nowAddress = `${address} ${nation}-${city}-${province}-${district}-${street}-${street_number}`;
        wx.showModal({
          title: "装换后的地理",
          content: nowAddress,
        });
      }
    },
  });
};
